package com.atguigu.flink.chapter05.transform;

import com.atguigu.flink.bean.WaterSensor;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author liuyun
 * @title: Flink11_Sum_All
 * @projectName flink0924
 * @description: TODO
 * @date 2022-3-3 15:32
 */
public class Flink11_Sum_All {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 20000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);

        DataStreamSource<WaterSensor> stream = env.fromElements(
                new WaterSensor("sensor_1", 1L, 10),
                new WaterSensor("sensor_1", 3L, 10),
                new WaterSensor("sensor_1", 4L, 10),
                new WaterSensor("sensor_1", 2L, 10),
                new WaterSensor("sensor_1", 5L, 10),
                new WaterSensor("sensor_1", 4L, 10),
                new WaterSensor("sensor_2", 5L, 10),
                new WaterSensor("sensor_2", 4L, 10)
        );

        stream.keyBy(value -> "a").sum("vc").print();
        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
